#include <cstring>
#include <iostream>
#include <deque>

#define x first
#define y second

using namespace std;

const int N = 510;

typedef pair<int, int> PII;

int n, m;
char g[N][N];
int dist[N][N];
bool st[N][N];

int bfs() {
    memset(dist, 0x3f, sizeof dist), memset(st, 0, sizeof st);
    
    deque<PII> q;
    dist[0][0] = 0;
    q.push_back({0, 0});
    
    char sc[] = "\\/\\/";
    int dx[4] = {-1, -1, 1, 1}, dy[4] = {-1, 1, 1, -1};
    int ix[4] = {-1, -1, 0, 0}, iy[4] = {-1, 0, 0, -1};
    
    while (q.size()) {
        auto t = q.front();
        q.pop_front();
        
        int xx = t.x, yy = t.y;
        
        if (xx == n & yy == m) return dist[n][m];
        
        if (st[xx][yy]) continue;
        st[xx][yy] = true;
        
        for (int i = 0; i < 4; ++ i) {
            int a = xx + dx[i], b = yy + dy[i];
            if (a < 0 || a > n || b < 0 || b > m) continue;
            
            int ga = xx + ix[i], gb = yy + iy[i]; 
            int w = (g[ga][gb] != sc[i]), d = dist[xx][yy] + w;
            if (d < dist[a][b]) {
                dist[a][b] = d;
                if (w) q.push_back({a, b});
                else q.push_front({a, b});
            }
        }
    }
}

int main() {
    int T;
    cin >> T;
    
    while (T -- ) {
        cin >> n >> m;
        for (int i = 0; i < n; ++ i) scanf("%s", g[i]);
        
        if ((n + m) & 1) puts("NO SOLUTION");
        else printf("%d\n", bfs());
    }
    
    return 0;
}